back to Creeper World
# Immortal-Volcano.crpl
# Created by: nathanaelps
# Created on: 8/28/2020 12:04:36 PM
# ------------------------------------------

$SporeCount:6
$SporeDelay:1 #seconds
$SporeHealthMin:1
$SporeHealthMax:1
$SporePayloadMin:5
$SporePayloadMax:45
$MaxDepth:40
$MaxRange:20
$FloodDepth:1

$IsFlipped:0
$Unhatch:0

once @initialize endonce

getTimer0 eq0 if
  <-Unhatch if @unhatch endif
  <-IsFlipped not if
    @checkForFlip
  else
    <-IsDead if
      CurrentCoords 0 SetCreeperMax
      @shouldWeRaise
    else
      @shouldWeKill
    endif
  endif
  10 SetTimer0
endif

getTimer1 eq0 if
  <-IsDead not
    <-SporeDelay 10 mul 0 RandInt 1 eq and if @spawnSpore endif
  3 SetTimer1
endif

#-------------------------------

:initialize
  #ShowTraceLog
  0 @setDead
  @setName
  Self CONST_NULLIFIERDAMAGES 0 SetUnitAttribute
  Self CONST_CREATEPZ 0 SetUnitAttribute
  <-IsFlipped if 1 @setIsFlipped endif

:checkForFlip
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-flooded if 1 @setIsFlipped endif

:shouldWeRaise
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-flooded not if 0 @setDead endif

:shouldWeKill
  CurrentCoords GetCreeper 0 <-FloodDepth sub lt ->flooded
  <-IsFlipped <-flooded and if 1 @setDead endif

:unhatch
  "CRPLCORE" CurrentCoords CreateUnit ->unit
  <-unit "Immortal-VolcanoVent.crpl" AddScriptToUnit
  <-unit "Immortal-VolcanoVent.crpl" "SporeCount" <-SporeCount SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "SporeDelay" <-SporeDelay SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "SporeHealthMin" <-SporeHealthMin SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "SporeHealthMax" <-SporeHealthMax SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "SporePayloadMin" <-SporePayloadMin SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "SporePayloadMax" <-SporePayloadMax SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "MaxRange" <-MaxRange SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "MaxDepth" <-MaxDepth SetScriptVar
  <-unit "Immortal-VolcanoVent.crpl" "FloodDepth" <-FloodDepth SetScriptVar
  Self 0 Destroy

:spawnSpore
  <-isDead not #if
    <-MaxDepth 0 gt CurrentCoords GetCreeper <-MaxDepth lt and and if
    <-SporeCount 0 do

      <-MaxRange 0 gt if
        CurrentCoords # -->
          CurrentCoords <-MaxRange RandCoordsInRange # -->
          <-SporeHealthMin <-SporeHealthMax 1 add RandInt # -->
          <-SporePayloadMin <-SporePayloadMax RandInt # -->
          CreateSpore
      else
        CurrentCoords RandCoords
          <-SporeHealthMin <-SporeHealthMax 1 add RandInt # -->
          <-SporePayloadMin <-SporePayloadMax RandInt # -->
          CreateSpore
      endif

    loop
  endif

:setDead
  ->IsDead
  @updateImage
  Self CONST_COUNTSFORVICTORY <-IsDead not SetUnitAttribute
  Self CONST_SUPPORTSDIGITALIS <-IsDead not SetUnitAttribute

:setIsFlipped
  ->IsFlipped



:updateImage #36 1.7
  36 ->ImageId
  Self "main" 1.7 1.7 SetImageScale
  <-IsFlipped if <-ImageId 2 add ->ImageId endif
  <-IsDead if <-ImageId 1 add ->ImageId endif
  Self "main" "Custom" <-ImageId Concat SetImage

:setName
  <-SporeCount " max spores, produced every " <-SporeDelay "s" Concat Concat Concat SetPopupText